package com.zhilei.controller;

import com.zhilei.base.BaseInfoProperties;
import com.zhilei.intercept.JWTCurrentUserInterceptor;
import com.zhilei.pojo.Users;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 志磊
 */
@RestController
@RequestMapping("/u")
@Slf4j
public class HelloController extends BaseInfoProperties {

    @Value("${server.port}")
    private String port;

    @GetMapping("/hello")
    public String hello(HttpServletRequest request) {
        // 通过请求获取请求头信息
        // String header = request.getHeader(APP_USER_JSON);

        // 测试通过本地线程获取用户信息
        Users users = JWTCurrentUserInterceptor.USER_THREAD.get();
        log.error("users； {}", users);

        // 将头部信息使用反射到user中
        // Users user = new Gson().fromJson(header, Users.class);
        // log.error("user； {}", user);
        return "hello user-service, port: " + users;
    }
}
